package com.wsc.springbootmultidevdemo.msg.workq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wsc.springbootmultidevdemo.msg.ConnectionUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * MQ Work Queues
 */
@Slf4j
public class Producer {

    private final static String QUEUE_NAME = "Work Queues";

    public static void main(String[] args) throws InterruptedException, TimeoutException, IOException {
        send();
    }

    private static void send() throws IOException, TimeoutException, InterruptedException {
        //获得MQ连接
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        for (int i = 0; i <100 ; i++) {
            String message = "message:"+i;
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
            log.info("[X] send message:"+message);
            Thread.sleep(100);
        }

        channel.close();
        connection.close();

    }

}
